import { type Ref, onMounted, onUnmounted } from "vue";
// 监听元素大小变化
export function useResizeObserver(
  target: Ref<Element | null>,
  callback: (entries: ResizeObserverEntry[]) => void
): ResizeObserver {
  const resizeObserver = new ResizeObserver(callback);

  onMounted(() => {
    if (target.value) {
      resizeObserver.observe(target.value);
    }
  });

  onUnmounted(() => {
    resizeObserver.disconnect();
  });
}
